﻿// Public.js 文件
function Request(strName)
{
	var url = location.search;
	var reg = new RegExp("(^|&)" + strName + "=([^&]*)(&|$)");
	var r = url.substr(url.indexOf("?") + 1).match(reg);
	if (r != null)
		return unescape(r[2]);
	return null;
}

function GetRandNumber(Number)
{
	return Math.ceil(Math.random() * Number);
}

//增加 trim(),ltrim(),rtrim() 四个函数
String.prototype.ltrim = function()	{return ltrim(this);}
String.prototype.rtrim = function()	{return rtrim(this);}
String.prototype.rtrimWithReturn = function()	{return rtrimWithReturn(this);}
String.prototype.trim = function()	{return trim(this);}

//此处为独立函数 
function ltrim(str)
{
	var i;
	for(i = 0; i< str.length; i++)
	{
		if (str.charAt(i) != " " && str.charAt(i) != " ")
			break;
	}
	str = str.substring(i, str.length);
	return str;
}

function rtrim(str)
{
	var i;
	for(i = str.length - 1; i >= 0; i--)
	{
		if (str.charAt(i) != " " && str.charAt(i) != " ")
			break;
	}
	str = str.substring(0, i + 1);
	return str;
}

function rtrimWithReturn(str)
{
	var i;
	for(i = str.length - 1; i >= 0; i--)
	{
		if (str.charAt(i) != " " && str.charAt(i) != " " && str.charAt(i) != "\n")
			break;
	}
	str = str.substring(0, i + 1);
	return str;
}

function trim(str)
{
	return ltrim(rtrim(str));
}

function DateToString(datetime)
{
	return datetime.getYear() + "-" + (datetime.getMonth() + 1) + "-" + datetime.getDate() + " " + datetime.getHours() + ":" + datetime.getMinutes() + ":" + datetime.getSeconds();
}

function StrToInt(str)
{
	str = str.trim();
	if (str == "")
		return 0;
		
	var i = parseInt(str, 10);
	if (isNaN(i))
		return 0;
	
	return i;
}

function StrToFloat(str)
{
	var NewStr = "";
	for(var i = 0; i< str.length; i++)
	{
		if (str.charAt(i) != "," && str.charAt(i) != " ")
			NewStr += str.charAt(i);
	}

	if (NewStr == "")
		return 0;
		
	var f = parseFloat(NewStr);
	if (isNaN(f))
		return 0;
	
	return f;
}

function Round(Num, Len)
{
	var temp = 1;
	for (var i = 0; i < Len; i++)
		temp *= 10;

	return Math.round(Num * temp) / 100;
}

function document.onkeydown()//关F5
{
	if (event.keyCode == 116)
    {
		event.keyCode = 0;
		event.cancelBubble = true;        
		return false;
	}
}

//function document.oncontextmenu()//关右键菜单
//{
//	return false;
//}

function BuildHtmlText(FontName, FontSize, FontColor, Text)
{
	return "<font face=\"" + FontName + "\" size=\"" + FontSize + "\" color=\"" + FontColor + "\">" + Text + "</font>"
}

/*
function HelloWordOfTime()
{
	var hour = (new Date()).getHours();
	
	if (hour >= 8 && hour <= 11)
		return "上午好！";
	else if ((hour >= 11) && (hour <= 13))
		return "中午好！";
	else if ((hour >= 13) && (hour <= 19))
		return "下午好！";
	else if ((hour >= 19) && (hour <= 23))
		return "晚上好！";
	else if ((hour >= 23) || (hour <= 5))
		return "深夜好！";
	else
		return "清晨好！";
}

function toUTF8(szInput)
{ 
	var wch, x, uch = "", szRet = "";
	for (x=0; x < szInput.length; x++)
	{
		wch = szInput.charCodeAt(x);
		if (!(wch & 0xFF80))
		{
			szRet += szInput.charAt(x);
		}
		else if (!(wch & 0xF000))
		{
			uch = "%" + (wch>>6 | 0xC0).toString(16) + "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch; 
		}
		else
		{
			uch = "%" + (wch >> 12 | 0xE0).toString(16) + "%" + (((wch >> 6) & 0x3F) | 0x80).toString(16) + "%" + (wch & 0x3F | 0x80).toString(16);
			szRet += uch;
		}
	}
	return(szRet);
}
*/

function ExchangeFootBallQuickBuy(ObjPrefix, Num, NumCount,L,P)
{
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
	    var TmpObjself = eval(ObjPrefix + i);
	    
		if(i == Num.toString())
		{
		   TmpObjself.className = ObjPrefix + "Index";
		}
		else
		{
		   TmpObjself.className =  ObjPrefix + "Other";
		}
	}

	if (L.toString() == "1")
	{
	    if (P.toString() == "101")
	    {
	        document.all["FootBallQuickBuy"].src="QuickBuy/SFC.aspx";
	    }
	    else
	    {
	        document.all["FootBallQuickBuy"].src="QuickBuy/SFC_9.aspx";
	    }
	}
	else if (L.toString() == "2")
	{
	    document.all["FootBallQuickBuy"].src="QuickBuy/JQC.aspx";
	}
	else if (L.toString() == "15")
	{
	    document.all["FootBallQuickBuy"].src="QuickBuy/LCBQC.aspx";
	}
	else
	{
	    document.all["FootBallQuickBuy"].src="QuickBuy/SFC.aspx";
	}
}

function ExchangeSchemesMenu(ObjPrefix, Num, NumCount,L)
{
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
	    var TmpObjself = eval(ObjPrefix + i);
	    
		if(i == Num.toString())
		{
		   TmpObjself.className = ObjPrefix + "Index";
		}
		else
		{
		   TmpObjself.className =  ObjPrefix + "Other";
		}
	}
	document.all["FootBallSchemesList"].src="FootBallSchemesList.aspx?LotteryID=" + L.toString();
}

function ExchangeDivForFootball(ObjPrefix, Num, NumCount)
{
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
	    var TmpObj1 = eval(ObjPrefix + "1_1");
	    var TmpObjself = eval(ObjPrefix + i);
        var TmpObj = eval(ObjPrefix + i + "_1");
	    var TmpObjselflink = eval(ObjPrefix + "l" + i);
	    
		if(i == Num.toString())
		{
		   TmpObjself.className = ObjPrefix + "Index";
		   TmpObjselflink.className = "hei";
	       TmpObj.style.display='';
		}
		else
		{
		   TmpObjself.className =  ObjPrefix + "Other";
		   TmpObjselflink.className = "bai1";
	       TmpObj.style.display='none';
		}
	}
}

function ExchangeDivMenu(ObjPrefix, Num, NumCount)
{
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
	    var TmpObjself = eval(ObjPrefix + i);
	    var TmpObj = eval(ObjPrefix + i + "_1");
		if(i == Num.toString())
		{
		   TmpObjself.className = ObjPrefix + "Index";
		   TmpObj.style.display='';
		}
		else
		{
		   TmpObjself.className =  ObjPrefix + "Other";
		   TmpObj.style.display='none';
		}
	}
}

function ExchangeDiv(ObjPrefix, Num, NumCount)
{
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
	    var TmpObjself = eval(ObjPrefix + i);
	    var TmpObj = eval(ObjPrefix + i + "_1");
		if(i == Num.toString())
		{
		   TmpObjself.className = ObjPrefix + "Index";
		   TmpObj.style.display='';
		}
		else
		{
		   TmpObjself.className = ObjPrefix + "Other";
		   TmpObj.style.display='none';
		}
	}
	
	ScrollInit();
}

function BrowserType()
{
    this.ver = navigator.appVersion;
    this.agent = navigator.userAgent;
    this.dom = document.getElementById ? 1 : 0;
    this.opera5 = this.agent.indexOf("Opera 5") > -1;
    this.ie5 = (this.ver.indexOf("MSIE 5") > -1 && this.dom && !this.opera5) ? 1 : 0; 
    this.ie6 = (this.ver.indexOf("MSIE 6") > -1 && this.dom && !this.opera5) ? 1 : 0;
    this.ie4 = (document.all && !this.dom && !this.opera5) ? 1 : 0;
    this.ie = this.ie4 || this.ie5 || this.ie6
    this.mac = this.agent.indexOf("Mac") > -1
    this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0; 
    this.ns4 = (document.layers && !this.dom) ? 1 : 0;
    this.bwt = (this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
    
    return this;
}
var bwt = new BrowserType();

var speed = 30;

var loop, timer;

var ScrollContent = false;

var oScroll;
function makeObj(obj,nest)
{
    nest = (!nest) ? "" : 'document.' + nest + '.';
    this.el = bwt.dom ? document.getElementById(obj) : bwt.ie4?document.all[obj]:bwt.ns4?eval(nest + 'document.' + obj):0;
    this.style = bwt.dom ? document.getElementById(obj).style : bwt.ie4?document.all[obj].style:bwt.ns4?eval(nest + 'document.' + obj):0;
    this.scrollHeight = bwt.ns4 ? this.style.document.height : this.el.offsetHeight;
    this.clipHeight = bwt.ns4 ? this.style.clip.height:this.el.offsetHeight;
    this.up = goUp;this.down = goDown;
    this.moveIt = moveIt; this.x = 0; this.y = 0;
    this.obj = obj + "Object";
    eval(this.obj + "=this")
    return this
}

function makeObj(obj,nest)
{
    nest = (!nest) ? "":'document.' + nest + '.';
    this.el = bwt.dom?document.getElementById(obj):bwt.ie4?document.all[obj]:bwt.ns4?eval(nest + 'document.' + obj):0;
    this.style = bwt.dom?document.getElementById(obj).style:bwt.ie4?document.all[obj].style:bwt.ns4?eval(nest + 'document.' + obj):0;
    this.scrollHeight = bwt.ns4?this.style.document.height:this.el.offsetHeight;
    this.clipHeight = bwt.ns4?this.style.clip.height:this.el.offsetHeight;
    this.up = goUp;this.down = goDown;
    this.moveIt = moveIt; this.x = 0; this.y = 0;
    this.obj = obj + "Object";
    eval(this.obj + "=this");
    return this
}

var px = bwt.ns4 || window.opera ? "" : "px";

function moveIt(x,y)
{
    this.x = x;
    this.y = y;
    this.style.left = this.x + px;
    this.style.top = this.y + px;
}

function goDown(move)
{
    if (this.y > -this.scrollHeight + oCont.clipHeight)
    {
        this.moveIt(0,this.y - move);
        if (loop) setTimeout(this.obj + ".down(" + move + ")",speed);
    }
}

function goUp(move)
{
    if (this.y < 0)
    {
        this.moveIt(0,this.y - move);
        if (loop) setTimeout(this.obj + ".up(" + move + ")",speed);
    }
}

function ScrollMove(speed)
{
    if (!oScroll)
    {
        oCont = new makeObj('divScrollContent');
        oScroll = new makeObj('divScrollContentSon','divScrollContent');
        oScroll.moveIt(0,0);
        ScrollContent = true;
    }
    
    if (ScrollContent)
    {
        loop = true;
        if (speed > 0)
        {
            oScroll.down(speed);
        }
        else
        {
            oScroll.up(speed);
        }
    }
}

function noScroll()
{
    loop = false
    if (timer)
    {
        clearTimeout(timer);
    }
}

function ScrollInit()
{
    oCont = new makeObj('divScrollContent');
    oScroll = new makeObj('divScrollContentSon','divScrollContent');
    oScroll.moveIt(0,0);
    ScrollContent = true;
}

var CurrentOpenWin = 1;
function NextResult(ObjPrefix,TmpCurrent,NumCount)
{
	if (TmpCurrent >= NumCount)
	{
		TmpCurrent = NumCount;
	}

	if (TmpCurrent <= 1)
	{
		TmpCurrent = 1;
	}
	for(var i = 1; i <= parseInt(NumCount); i++)
	{
		var TmpObjself = eval(ObjPrefix + i);
		var TmpObj = eval(ObjPrefix + i + "_1");
		if(i == TmpCurrent.toString())
		{
		   TmpObjself.style.display='';
		   TmpObj.style.display='';
		}
		else
		{
		   TmpObjself.style.display='none';
		   TmpObj.style.display='none';
		}
	}
	CurrentOpenWin = TmpCurrent;
}

function CheckMoneyOnPress()
{
	if (window.event.keyCode < 48 || window.event.keyCode > 57)
	{
		return false;
    }
    		
	return true;
}

function CheckMoneyOnPressDecimal(sender)
{
  //if(sender.value.search(/[0-9]{1,}.[0-9]{1,}/) != 0) 
  if(sender.value.search(/[0|1].[0-9]{1,}/) != 0) 
  {    
        sender.value = "";
        sender.focus();
  }
}

function WinOpen(Url, Height, Width)
{
    window.open (Url, 'newwindow', 'height= ' + Height + ', width=' + Width + ', top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
}

function ShowFlash(Obj, Url, Width, Height)
{
    Obj.document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + Width + '" height="' + Height + '">');
    Obj.document.write('<param name="allowScriptAccess" value="sameDomain"><param name="movie" value="' + Url +'"> <param name="quality" value="high">');
    Obj.document.write('<param name="menu" value="false"><param name=wmode value="opaque">');
    Obj.document.write('<embed src="' + Url + '" wmode="opaque" />');
    Obj.document.write('</object>');
}
